﻿@using Masuit.MyBlogs.Core.Common
@using Masuit.Tools.Html
@using CacheManager.Core
@using Masuit.MyBlogs.Core.Views.Post
@model Masuit.MyBlogs.Core.Models.DTO.PostDto
@inject ICacheManager<HashSet<string>> CacheManager
@{
    string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
    var online = CacheManager.Get(nameof(PostOnline) + ":" + Model.Id)?.Count ?? 0;
}

<div class="ibox wow fadeIn">
    <div class="ibox-content">
        <a asp-controller="Post" asp-action="Details" asp-route-id="@Model.Id" target="_blank">
            <h4>
                @if (Model.IsFixedTop)
                {
                    <i class="icon-thumbsup fixtop">[顶]</i>
                }
                @if (DateTime.Now - Model.ModifyDate < TimeSpan.FromDays(1))
                {
                    <i class="new">[新]</i>
                }
                @Model.Title
            </h4>
        </a>
        <div class="row padding-bot10">
            @{
                //取第一张图片
                string imgSrc = Model.Content.MatchFirstImgSrc();
                if (!string.IsNullOrEmpty(imgSrc))
                {
                    <div class="col-md-2 paddingright-clear hidden-xs">
                        <img class="img-thumbnail img-responsive thumb" data-original="@imgSrc" alt="@CommonHelper.SystemSettings["Title"]" title="@CommonHelper.SystemSettings["Title"] ">
                    </div>
                }
            }
            <div class="col-md-@(string.IsNullOrEmpty(imgSrc) ? 12 : 10)">
                <div class="small padding-bot10">
                    作者：<i class="icon-user-check"></i>
                    <strong class="label label-primary">
                        <a asp-controller="Home" asp-action="Author" asp-route-author="@(Model.Modifier??Model.Author)">@(Model.Modifier??Model.Author)</a>
                    </strong>
                    <span class="text-muted">
                        | 发表时间：<i class="fa fa-clock-o"></i> @Model.ModifyDate.ToString("yyyy-MM-dd HH:mm") | 分类：<i class="icon-map-pin"></i>
                        <a asp-controller="Home" asp-action="Category" asp-route-id="@Model.CategoryId">@Model.CategoryName</a>
                    </span>
                </div>
                <p>
                    @Html.Raw(await Model.Content.GetSummary(150, 50))
                </p>
            </div>
        </div>
        <div class="row">
            @if (!string.IsNullOrEmpty(Model.Label))
            {
                var tags = Model.Label.Split(',', '，');
                <div class="col-md-6">
                    @for (var i = 0; i < tags.Length; i++)
                    {
                        <a asp-controller="Home" asp-action="Tag" asp-route-tag="@tags[i]" target="_blank">
                            <span class="label label-@colors[i]">@tags[i]</span>
                        </a>
                    }
                </div>
            }
            <div class="col-md-6 pull-right">
                <div class="small text-right">
                    <i class="fa fa-eye"></i>@online 在看 |
                    <i class="fa fa-comments-o"></i>@Model.CommentCount 评论 |
                    <i class="fa fa-eye"></i>@Model.TotalViewCount 浏览 |
                    <i class="icon-thumbsup"></i>@Model.VoteUpCount 支持
                </div>
            </div>
        </div>
    </div>
</div>
